/*
** ADOBE SYSTEMS INCORPORATED
** Copyright 2012 Adobe Systems Incorporated
** All Rights Reserved.
**
** NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the
** terms of the Adobe license agreement accompanying it.  If you have received this file from a
** source other than Adobe, then your use, modification, or distribution of it requires the prior
** written permission of Adobe.
*/
#include "MurmurHash3.h"
#include <stdlib.h>
#include "AS3/AS3.h"

// First we mark the function declaration with a GCC attribute specifying the
// AS3 signature we want it to have in the generated SWC. The function will
// be located in the sample.MurmurHash namespace.
void MurmurHash3() __attribute__((used,
	annotate("as3sig:public function MurmurHash3(keystr:String):uint"),
	annotate("as3package:sample.MurmurHash")));

void MurmurHash3()
{
    // Copy the AS3 string to the C heap (must be free'd later)
    char *key = NULL;
    AS3_MallocString(key, keystr);

    int keylen = 0;
    AS3_StringLength(keylen, keystr);
    
    // Call hash function
    int result;
    uint32_t seed = 42;
    MurmurHash3_x86_32(key, keylen, seed, &result);
    
    // don't forget to free the string we allocated with malloc previously
    free(key);
    
    // return the result (using an AS3 return rather than a C/C++ return)
    AS3_Return(result);
}
